import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/main',
    name: 'main',

    component: () => import('../views/MainView.vue'),
    children:[
      {
        path:'/main/daka',
        name:'daka',
        component:()=>import('../views/DaKaView.vue')
      },
      {
        path:'/main/submit',
        name:'submit',
        component:()=>import('../views/SubMitView.vue')
      },
      {
        path: '',
    name: 'tubiao',
    component: () => import('../views/TubiaoView.vue')
      },
      {
        path:"/main/wuzi1",
        name: 'wuzi1',
    component: () => import('../views/WuZiManageView.vue')
      },
      {
        path:"/main/wuzi2",
        name: 'wuzi2',
    component: () => import('../views/WuZiBuyView.vue')
      },
      {
        path:"/main/wuzi3",
        name: 'wuzi3',
    component: () => import('../views/WuZiShareView.vue')
      },
      {
        path:"/main/wuzi4",
        name: 'wuzi4',
    component: () => import('../views/WuZiRequestView.vue')
      },
      {
        path:"/main/wuzi5",
        name: 'wuzi5',
    component: () => import('../views/WuZiQueryView.vue')
      },
      {
        path:"/main/peoplemanage",
        name: 'peoplemanage',
    component: () => import('../views/PeopleManageView.vue')
      },
      {
        path:"/main/tubiao",
        name: 'tubiao',
    component: () => import('../views/TubiaoView.vue')
      },
      {
        path:"/main/liaotian",
        name: 'liaotian',
    component: () => import('../views/WebSocketView.vue')
      },
      {
        path:"/main/upload",
        name: 'upload',
    component: () => import('../views/UpLoadView.vue')
      },
      {
        path:"/main/upload2",
        name: 'upload2',
    component: () => import('../views/UpLoad2View.vue')
      }



    ]
    
  },
  {
    path:"/text",
    name: 'upload2',
component: () => import('../views/TextView.vue')
  }
  

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  const token =localStorage.getItem('token')
  if(to.name !='login' && !token) next({name : 'login'})
  else next()

  
})

export default router
